﻿using STHPMS1.Common.C_Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using STHPMS1.Common.C_Extension;
using Newtonsoft.Json;
using STHPMS1.Web.W_Model.EnumModel;
using STHPMS1.ICore.I_Entity.Info;
namespace STHPMS1.Web.W_Controller
{
    [RoutePrefix("api/data")]
    public class DataController : STHPMS1.Web.W_Core.MyController
    {
        /// <summary>
        /// 获取行政区域编码json
        /// </summary>
        /// <returns></returns>
        [Route("regioncode")]
        public IHttpActionResult GetRegionCode()
        {
            return Ok(this.Scene.Data.RegionCodeEnum);
        }

        /// <summary>
        /// 获取行政区域编码json
        /// </summary>
        /// <returns></returns>
        [Route("code")]
        public IHttpActionResult GetCode()
        {
            Dictionary<int, string> dict = new Dictionary<int, string>();
            RecursiveCode(dict,this.Scene.Data.RegionCodeEnum);
            return Ok(dict);
        }

        private void  RecursiveCode(Dictionary<int, string> dict,IEnumerable<IRegionCodeInfo> codes)
        {
            if (codes == null) return;
            foreach (var item in codes)
            {
                if(item.id!=0)
                    dict.Add(item.id, item.text);
                RecursiveCode(dict, item.child);
            }
        }


        /// <summary>
        /// 获取方向编码jjson
        /// </summary>
        /// <returns></returns>
        [Route("direction")]
        public IHttpActionResult GetDirection()
        {
            return Ok(this.Scene.Data.DirectionEnum);
        }
        /// <summary>
        /// 获取行政等级编码json
        /// </summary>
        /// <returns></returns>
        [Route("adminlevel")]
        public IHttpActionResult GetAdminLevel()
        {
            return Ok(this.Scene.Data.AdminLevelEnum);
        }
        /// <summary>
        /// 获取路面类型编码json
        /// </summary>
        /// <returns></returns>
        [Route("pavement")]
        public IHttpActionResult GetPavementType()
        {
            return Ok(this.Scene.Data.PavementTypeEnum);
        }
        
        /// <summary>
        /// 获取层材料编码json
        /// </summary>
        /// <param name="l">路面类型</param>
        /// <returns></returns>
        [Route("layer")]
        public IHttpActionResult GetLayer(int? l)
        {
            int layer = l ?? 0;
            IEnumerable<IComboxJsonInfo> result = null;
            switch (layer)
            {
                case 0:
                    result = this.Scene.Data.LayerEnum;
                    break;
                case 30:
                    {
                        result = this.Scene.Data.TopLayerEnum;
                        break;
                    }
                case 45:
                    {
                        result = this.Scene.Data.MiddleLayerEnum;
                        break;
                    }
                case 50:
                    {
                        result = this.Scene.Data.DownLayerEnum;
                        break;
                    }
                case 55:
                    {
                        result = this.Scene.Data.BasicLayerEnum;
                        break;
                    }
                case 75:
                    {
                        result = this.Scene.Data.SubbaseLayerEnum;
                        break;
                    }
                case 95:
                    {
                        result = this.Scene.Data.CushionLayerEnum;
                        break;
                    }
                default: 
                    break;
            }
            if (result == null) return null;
            return Ok(result);
        }

        /// <summary>
        /// 获取层材料编码json
        /// </summary>
        /// <param name="l">路面类型</param>
        /// <returns></returns>
        [Route("layer2")]
        public IHttpActionResult GetLayer()
        {
            return Ok(this.Scene.Data.LayerEnum);
        }
        /// <summary>
        /// 获取结构编码json
        /// </summary>
        /// <param name="s">结构层类型</param>
        /// <returns></returns>
        [Route("sturcture")]
        public IHttpActionResult GetSturcture(int? s)
        {
            int sturcture = s ?? 0;
            IEnumerable<IComboxJsonInfo> result = null;
            switch (sturcture)
            {
                case 0:
                    result = this.Scene.Data.SturctureEnum;
                    break;
                case 111:
                    {
                        result = this.Scene.Data.BridgeEnum;
                        break;
                    }
                case 120:
                    {
                        result = this.Scene.Data.TunnelEnum;
                        break;
                    }
                case 125:
                    {
                        result = this.Scene.Data.CulvertEnum;
                        break;
                    }
                default:
                    break;
            }
            if (result == null) return null;
            return Ok(result);
        }
        /// <summary>
        /// 获取技术等级编码json
        /// </summary>
        /// <param name="t">结构层类型</param>
        /// <returns></returns>
        [Route("technical")]
        public IHttpActionResult GetTechnical(int? t)
        {
            int technical = t ?? 0;
            IEnumerable<IComboxJsonInfo> result = null;
            switch (technical)
            {
                case 111:
                    {
                        result = this.Scene.Data.BridgeTechnicalEnum;
                        break;
                    }
                case 120:
                    {
                        result = this.Scene.Data.TunnelTechnicalEnum;
                        break;
                    }
                default:
                    result = new List<IComboxJsonInfo>();
                    break;
            }
            if (result == null) return null;
            return Ok(result);
        }
        /// <summary>
        /// 道路技术等级编码json
        /// </summary>
        /// <returns></returns>
        [Route("roadclass")]
        public IHttpActionResult GetRoadClass()
        {
            return Ok(this.Scene.Data.RoadClassEnum);
        }
        /// <summary>
        /// 路面基层类型编码json
        /// </summary>
        /// <returns></returns>
        [Route("roadbasic")]
        public IHttpActionResult GetRoadBasicTypeEnum()
        {
            return Ok(this.Scene.Data.RoadBasicTypeEnum);
        }
        /// <summary>
        /// 土基类型编码json
        /// </summary>
        /// <returns></returns>
        [Route("subgrade")]
        public IHttpActionResult GetSubgradeEnum()
        {
            return Ok(this.Scene.Data.SubgradeEnum);
        }
        /// <summary>
        /// 路肩类型编码json
        /// </summary>
        /// <returns></returns>
        [Route("shoulder")]
        public IHttpActionResult GetShoulderEnum()
        {
            return Ok(this.Scene.Data.ShoulderEnum);
        }
        /// <summary>
        /// 路缘石类型编码json
        /// </summary>
        /// <returns></returns>
        [Route("curb")]
        public IHttpActionResult GetCurbEnum()
        {
            return Ok(this.Scene.Data.CurbEnum);
        }

      
        /// <summary>
        /// 汽车类型 json
        /// </summary>
        /// <returns></returns>
        [Route("car")]
        public IHttpActionResult GetCarEnum()
        {
            return Ok(this.Scene.Data.CarEnum);
        }  
        /// <summary>
        /// 事故原因 json
        /// </summary>
        /// <returns></returns>
        [Route("accreason")]
        public IHttpActionResult GetAccidentCauseEnum()
        {
            return Ok(this.Scene.Data.AccidentCauseEnum);
        }
        /// <summary>
        /// 事故类型 json
        /// </summary>
        /// <returns></returns>
        [Route("acctype")]
        public IHttpActionResult GetAccidentTypeEnum()
        {
            return Ok(this.Scene.Data.AccidentTypeEnum);
        }

        /// <summary>
        /// 评定等级
        /// </summary>
        /// <returns></returns>
        [Route("evalucalss")]
        public IHttpActionResult GetEvalucalssEnum()
        {
            return Ok(this.Scene.Data.EvalucalssEnum);
        }

        /// <summary>
        /// 评价指标
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("target")]
        public IHttpActionResult GetTargetEnum(string id)
        {
           
            if(id=="0")
            {
                return Ok(this.Scene.Data.GFTargetEnum); 
            }
            else
            {
                return Ok(this.Scene.Data.HMTargetEnum); 
            }
        }

        /// <summary>
        /// 养护类型
        /// </summary>
        /// <returns></returns>
        [Route("maintype")]
        public IHttpActionResult GetMainTypeEnum()
        {
            return Ok(this.Scene.Data.MainTypeEnum);
        }

        /// <summary>
        /// 数据导入类型
        /// </summary>
        /// <returns></returns>
        [Route("importtype")]
        public IHttpActionResult GetImportTypeEnum()
        {
            return Ok(this.Scene.Data.ImportTypeEnum);
        }

        /// <summary>
        /// 年份
        /// </summary>
        /// <returns></returns>
        [Route("years")]
        public IHttpActionResult GetYearsEnum()
        {
            return Ok(this.Scene.Data.YearEnum);
        }


        /// <summary>
        /// 分析类型
        /// </summary>
        /// <returns></returns>
        [Route("anastype")]
        public IHttpActionResult GetAnasTypeEnum()
        {
            return Ok(this.Scene.Data.AnasTypeEnum);
        }

        /// <summary>
        /// 资金类型
        /// </summary>
        /// <returns></returns>
        [Route("annutype")]
        public IHttpActionResult GetAnnuTypeEnum()
        {
            return Ok(this.Scene.Data.AnnuTypeEnum);
        }

    }
}